package com.gollum.web.controller.auth;

import com.gollum.common.annotation.FlowLimiter;
import com.gollum.common.constant.GollumLimterConstants;
import com.gollum.common.domain.response.RestResponse;
import com.gollum.common.enums.LimitType;
import com.gollum.common.web.controller.BaseController;
import com.gollum.web.service.CaptchaService;
import com.gollum.system.domain.request.CaptchaRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



/**
 * 验证码控制层
 *
 * @author Herther
 * @version 1.0.0
 * @createTime 2022年08月28日 21:21:00
 */
@Api(tags = "验证码中心")
@RestController
@RequestMapping("/auth")
public class CaptchaCodeController extends BaseController {

    @Autowired
    protected CaptchaService captchaService;


    /**
     * 生成验证码
     *
     * @auther: Herther
     * @version 1.0.0
     * @date: 2022/8/28 21:22
     */
    @GetMapping("/advCode")
    @ApiOperation(value = "生成高级验证码")
    public RestResponse generateCaptchaCode(){
        //TODO 后期根据系统配置生成对应的验证码
        return RestResponse.success(captchaService.generateCaptcha());
    }

    /**
     * 校验验证码
     *
     * @auther: Herther
     * @version 1.0.0
     * @date: 2022/8/28 23:08
     *
     */
    @PostMapping("/check")
    @ApiOperation(value = "校验验证码")
    public RestResponse checkCaptchaCode(CaptchaRequest requestBody){
        captchaService.checkCaptcha(requestBody);
        return RestResponse.success();
    }



    @GetMapping("/code")
    @ApiOperation(value = "普通图形验证码")
    @FlowLimiter(limitType = LimitType.IP, count = 10, key = GollumLimterConstants.CAPTCHA_LIMIT_KEY)
    public RestResponse genGrapCpatchaCode(){
        return RestResponse.success(captchaService.genGrapCpatchaCode());
    }



}
